//
//  MyServiceCell.m
//  PigMarket
//
//  Created by Felix on 2019/3/24.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "MyServiceCell.h"

@interface MyServiceCell ()
/**
 bgView
 */
@property (nonatomic , strong) UIView *bgView;
/**
 iconImageView
 */
@property (nonatomic , strong) UIImageView *iconImageView;
/**
 title
 */
@property (nonatomic , strong) UILabel *title;
/**
 badgeView
 */
@property (nonatomic , strong) UIImageView *badgeView;
/**
 badgeTitle
 */
@property (nonatomic , strong) UILabel *badgeTitle;

@end

@implementation MyServiceCell

#pragma mark - init method

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}
- (void)initView {
    // 添加子控件
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.iconImageView];
    [self.bgView addSubview:self.title];
    [self.contentView addSubview:self.badgeView];
    [self.badgeView addSubview:self.badgeTitle];
}

- (void)initLayout {
    // 布局子控件
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
        make.width.mas_equalTo(self.mas_width);
    }];
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.centerX.mas_equalTo(0);
//        make.left.right.mas_equalTo(0);
//        make.size.mas_equalTo(CGSizeMake(26, 26));
    }];
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.iconImageView.mas_bottom).offset(8);
        make.centerX.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
}

#pragma mark - getter and setter

- (void)setCellData:(NSDictionary *)cellData {
    _cellData = cellData;
    self.iconImageView.image = [UIImage imageNamed:cellData[@"icon"]];
    self.title.text = cellData[@"title"];
}

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
//        _bgView.backgroundColor = [UIColor redColor];
    }
    return _bgView;
}
- (UIImageView *)iconImageView {
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] init];
    }
    return _iconImageView;
}
- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.textColor = [UIColor colorWithHexString:@"#666666"];
        _title.font = [UIFont smallFont];
    }
    return _title;
}
- (UIImageView *)badgeView {
    if (!_badgeView) {
        _badgeView = [[UIImageView alloc] init];
    }
    return _badgeView;
}
- (UILabel *)badgeTitle {
    if (!_badgeTitle) {
        _badgeTitle = [[UILabel alloc] init];
    }
    return _badgeTitle;
}

@end
